
import React from 'react';

import styles from './RuleList.css';
import {Table, Divider, Tag, message} from 'antd';
import RuleService from "../../business/rule/RuleService";

const columns = [{
  title: '活动唯一标识',
  dataIndex: 'activityId',
  key: 'activityId',
  render: text => <a href="javascript:;">{text}</a>,
  fixed: 'left',
  width:80,
}, {
  title: '活动名称',
  dataIndex: 'activityName',
  key: 'activityName',
  fixed: 'left',
  width:300,
}, {
  title: '积分',
  dataIndex: 'points',
  key: 'points',
}, {
  title: '限制人群',
  dataIndex: 'limitedGroup',
  key: 'limitedGroup',
}, {
  title: '联系人',
  dataIndex: 'contactPerson',
  key: 'contactPerson',
}, {
  title: '主办方',
  dataIndex: 'host',
  key: 'host',
}, {
  title: '有效期',
  dataIndex: 'effectiveDate',
  key: 'effectiveDate',
  width:350,
  render:(text,record)=>{
    return text +" ~ "+record.expiredDate;
  }
}, {
  title: '状态',
  dataIndex: 'activeFlag',
  fixed: "right",
  key: 'activeFlag',
  width:100,
  render:(text, record)=>{
    if(text){
      return "有效";
    }else{
      return "无效";
    }
  }
}];
const rowSelection = {
  onChange: (selectedRowKeys, selectedRows) => {
  },
  getCheckboxProps: record => ({
    disabled: record.name === 'Disabled User',
    name: record.name,
  }),
};

class RuleList extends React.Component{

  constructor(props) {
    super(props);
    this.state ={
      giftData:[]
    }
    this.ruleService =new RuleService();
    this.callBackQueryList = this.callBackQueryList.bind(this);

  }
  ruleService:RuleService;
  state ={
    giftData:[]
  }

  callBackQueryList(giftList,isSuccess){
    if(!isSuccess || giftList.code !="200"){
      message.info(giftList.message);
    }else{
      this.setState({giftData: giftList.data});
    }
  }
  componentDidMount(){
    console.info("ruleListPage htpp start");
    this.ruleService.queryList(this.callBackQueryList);
  }

  show(giftData:any[]){
    if(giftData.length !=0){
     // @ts-ignore
      return (<Table columns={columns}
                    dataSource={giftData}
                    rowKey={record=>record.activityId}
                    scroll={{ x: 1400 }}/>);
    }else{
      return "";
    }
  }

  render() {
    const {giftData} = this.state;
    return (
      <div className={styles.normal}>
        {this.show(giftData)}
      </div>
    );
  }
}

export default RuleList;
